-
Notifications
You must be signed in to change notification settings - Fork 6
Refactor externalities usage #388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
alexggh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks alright to me, good job.
| } else { | ||
| // Else, we pop the front element | ||
| return_data_queue.pop_front() | ||
| } { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cargo fmt or what ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clippy lint application
* caching fix
59da939 to
bbc4cb2
Compare
| } | ||
| } | ||
|
|
||
| // Sync REVM state back to pallet-revive if this call was executed in REVM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please try to run the storage migration test:
function testStorageMigration() public {
SimpleStorage storageContract = new SimpleStorage();
// Mark the contract as persistent so it migrates
vm.makePersistent(address(storageContract));
storageContract.set(42);
assertEq(storageContract.get(), 42);
vm.pvm(false);
assertEq(storageContract.get(), 42);
storageContract.set(100);
assertEq(storageContract.get(), 100);
vm.pvm(true);
assertEq(storageContract.get(), 100);
}
I think it will fail without this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it indeed does.
However, if we move storage migration code inside select_revive to always migrate code then it does work.
also why do we need makePersistent? its purely a fork related cheatcode
edit:
makePersistent is a discount vm.register
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can put the storage migration code there, but I think we may have the issue with performance. You will need to sync all contracts - you do not have info which slot was modified.
Regarding makePersistent we used the same approach that zksync uses in select vm. They migrate persistent account as I remember. Maybe due to performance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can put the storage migration code there, but I think we may have the issue with performance.
i'll post the benchmarks on morpho test-suite, but it's definitely not the bottle neck as it could be visible there
You will need to sync all contracts - you do not have info which slot was modified.
we can use slot.is_cold() or compare the revm's slot value to current slot value before doing a write, but i doubt that will help with performance as we will still hash the key twice both for read and write
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you won’t see it in this test suite because the migration runs only once at the beginning, and all contracts with slots are migrated then (they are all newly created). The performance impact should become noticeable when you switch between EVMs many times — at that point it will be painful, because you will need to loop over all contract slots again and again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will impact fuzz tests when such cheatcode will be present.
I was thinking of having symmetric solution to this what we have with tracer when we are doing state migration from Revive to REVM. In this case we could skip all cheatcodes custom implementation which modify the storage and use the default implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will impact fuzz tests when such cheatcode will be present.
why would anyone go out their way to switch vm's in a lot of the fuzz tests?
In this case we could skip all cheatcodes custom implementation which modify the storage and use the default implementation.
not quite ass you'll need to migrate state slots for every contract touched during the test each time any cheatcode is called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point is that it is always a trade-off between doing things incrementally or as one large operation. Following this direction, we could also skip applying slot changes from the tracer in post_exec.
I prefer incremental changes, but it is OK for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it stands now if we remove state change functionality from the strategy and rely on duplicating the state via apply_revm_diff we would do the whole select_pvm thing on every cheatcode call to update the state on pallet_revive side of things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it is a problem, I had such PR but due to performance issues I put it on hold. We would need to have just list of changes.
filip-parity
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactoring should also solve DuplicateContract issues on macOS. Good job!
|
This also does not work, probably we need to migrate full state in select_evm anyway or do initial migration and later on incremental in both directions. It is not related to your changes, so we can address it as follow up |
Description
move away from thread-local.
see #286
Notes
ext.start_transactionext.rollback_transactionto save up time on cloning.crates/revive-strategy/state.rs, revm modifications happen through default cheatcode handlers in foundry.